#include <QCoreApplication>
#include "httplistener.h"
#include "HttpServerHandler.h"
#include "SqliteManager.h"

using namespace stefanfrings;

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    // 强制设置更大的线程池参数
    QSettings *settings = new QSettings("config.ini", QSettings::IniFormat);

    // 明确设置并打印关键参数
    settings->setValue("minThreads", 50);
    settings->setValue("maxThreads", 100);
    settings->setValue("maxRequestCount", 1000);
    settings->setValue("cleanupInterval", 1000);
    settings->sync();

    qDebug() << "=== 服务器配置验证 ===";
    qDebug() << "最小线程数:" << settings->value("minThreads").toInt();
    qDebug() << "最大线程数:" << settings->value("maxThreads").toInt();
    qDebug() << "最大请求数:" << settings->value("maxRequestCount").toInt();
    qDebug() << "配置文件:" << settings->fileName();

    // 初始化数据库
    SqliteManager::getInstance();

    // 启动HTTP服务器
    new HttpListener(settings, new HttpServerHandler(), &app);

    qInfo() << "🚀 服务器启动完成，端口:" << settings->value("port").toInt();
    qInfo() << "📊 配置: minThreads=" << settings->value("minThreads").toInt()
            << ", maxThreads=" << settings->value("maxThreads").toInt();

    return app.exec();
}
